package originMysql

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
	"sync"
)

type Person struct {
	UserId   int    `db:"user_id"`
	Username string `db:"username"`
	Sex      string `db:"sex"`
	Email    string `db:"email"`
}

type Place struct {
	Country string `db:"country"`
	City    string `db:"city"`
	TelCode int    `db:"telcode"`
}

var Db *sqlx.DB

func init() {
	var err error
	Db, err = sqlx.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/test")
	if err != nil {
		fmt.Println("open mysql failed,", err)
		return
	}

	//Db = database

}

func main11() {
	r, err := Db.Exec("insert into person(username, sex, email)values(?, ?, ?)", "stu001111", "man", "stu01@qq.com")
	defer func() {
		err := Db.Close()
		if err != nil {
			fmt.Println(err.Error())

		}
		fmt.Println("dddd")
	}()
	if err != nil {
		fmt.Println("exec failed, ", err)
		return
	}
	id, err := r.LastInsertId()
	if err != nil {
		fmt.Println("exec failed, ", err)
		return
	}
	panic(111)

	fmt.Println("insert succ:", id)

}

var c chan int = make(chan int, 10)
var s sync.WaitGroup
var a sync.Mutex

func demo() {

	defer s.Done()
	for i := 0; i < 100; i++ {
		fmt.Println(i)
	}
}
func test(s []string) {
	s[0] = "111"
	s[1] = "2222"
}
